package com.tsd.jxc.report.controller;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.tsd.core.annotation.ClientSupplier;
import com.tsd.core.utils.DateUtil;
import com.tsd.core.utils.HlpUtils;
import com.tsd.core.utils.ListUtil;
import com.tsd.core.vo.ErrorCode;
import com.tsd.core.vo.HttpResult;
import com.tsd.core.vo.PageBean;
import com.tsd.jxc.report.service.JxcReportService;
import com.tsd.jxc.report.vo.JxcBuySaleBillDetailVo;
import com.tsd.jxc.report.vo.JxcStockInOutBillInventoryVo;
import com.tsd.jxc.report.vo.JxcStockInOutBillReportVo;
import com.tsd.system.controller.SystemBaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.*;

/**
 * 描述：进销存-报表 控制层
 *
 * @author Hillpool
 * @date 2022/09/06 10:43:35
 */
@Controller
@Scope("prototype")
@RequestMapping("/api/v2")
@Api(tags = "进销存-统计报表", description = "进销存统计报表的API描述")
public class JxcReportController extends SystemBaseController {

    @Resource
    private JxcReportService jxcReportService;

    @ApiOperation(value = "进销存-统计报表-购销清单")
    @ResponseBody
    @RequestMapping(value = "/findBuySaleBillDetailReport.action", method = RequestMethod.POST)
    public HttpResult<Object> findBuySaleBillDetailReport() {
        HttpResult<Object> hr = new HttpResult<>();
        try {
            Map<String, Object> map = super.getParams(request);
            Map<String, Object> params = new HashMap<>(8);
            HlpUtils.copyIntegerValue(map, params, "audit_state", false, 0);
            HlpUtils.copyStringValue(map, params, "party_sid", false, false);
            HlpUtils.copyListValue(map, params, "party_list", false, String.class);
            HlpUtils.copyStringValue(map, params, "goods_sid", false, false);
            HlpUtils.copyListValue(map, params, "goods_list", false, String.class);
            HlpUtils.copyDateRangeValue(map, params, "bill_date", false);
            HlpUtils.copyStringValue(map, params, "search_value", false, false);
            PageBean page = new PageBean(map).procNoPage(map);
            List<JxcBuySaleBillDetailVo> list = jxcReportService.findBuySaleBillDetailReport(params, page);
            hr.setData(list);
            hr.setPage(page);
            hr.setCode(ErrorCode.CODE_SUCCESS);
        } catch (Exception e) {
            super.procException(hr, e);
        }
        return hr;
    }

    @ApiOperation(value = "进销存-统计报表-采购汇总报表", notes = "进销存-统计报表-采购汇总报表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "yyyy", value = "年份", required = false, dataType = "string", paramType = "form"),
    })
    @ResponseBody
    @RequestMapping(value = "/findBuyOrderCollectReportList.action", method = RequestMethod.POST)
    public HttpResult<Object> findBuyOrderReportList() {
        HttpResult<Object> hr = new HttpResult<>();
        try {
            Map<String, Object> map = super.getParams(request);
            Map<String, Object> params = new HashMap<>(8);
            HlpUtils.copyIntegerValue(map, params, "dr", "dr", false, 0);
            HlpUtils.copyStringValue(map, params, "yyyy", "yyyy", false, false, false);
            LinkedList<LinkedHashMap<String, Object>> list = jxcReportService.findBuyOrderReportList(params);
            hr.setData(list);
            hr.setCode(ErrorCode.CODE_SUCCESS);
        } catch (Exception e) {
            super.procException(hr, e);
        }
        return hr;
    }

    @ApiOperation(value = "进销存-统计报表-采购退货汇总报表", notes = "进销存-统计报表-采购退货汇总报表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "yyyy", value = "年份", required = false, dataType = "string", paramType = "form"),
    })
    @ResponseBody
    @RequestMapping(value = "/findBuyReturnCollectReportList.action", method = RequestMethod.POST)
    public HttpResult<Object> findBuyReturnCollectReportList() {
        HttpResult<Object> hr = new HttpResult<>();
        try {
            Map<String, Object> map = super.getParams(request);
            Map<String, Object> params = new HashMap<>(8);
            HlpUtils.copyIntegerValue(map, params, "dr", "dr", false, 0);
            HlpUtils.copyStringValue(map, params, "yyyy", "yyyy", false, false, false);
            LinkedList<LinkedHashMap<String, Object>> list = jxcReportService.findBuyReturnCollectReportList(params);
            hr.setData(list);
            hr.setCode(ErrorCode.CODE_SUCCESS);
        } catch (Exception e) {
            super.procException(hr, e);
        }
        return hr;
    }

    @ApiOperation(value = "进销存-统计报表-采购年度报表", notes = "进销存-统计报表-采购年度报表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", required = false, dataType = "string", paramType = "form"),
            @ApiImplicitParam(name = "pageNo", value = "页码", required = false, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "pageSize", value = "页大小，每页记录数", required = false, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "sorts", value = "排序设置，方式['property1 desc','property2']", required = false, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "totalRows", value = "总记录数，为了减少统计总记录数，一般从第二页开始前端提供totalRows", required = false, dataType = "int", paramType = "form")
    })
    @ResponseBody
    @RequestMapping(value = "/findBuyYearReportListByPage.action", method = RequestMethod.POST)
    public HttpResult<Object> findBuyYearReportListByPage() {
        HttpResult<Object> hr = new HttpResult<>();
        try {
            Map<String, Object> map = super.getParams(request);
            Map<String, Object> params = new HashMap<>(8);
            HlpUtils.copyIntegerValue(map, params, "dr", "dr", false, 0);
            HlpUtils.copyStringValue(map, params, "yyyy", "yyyy", false, false, false);
            HlpUtils.copyStringValue(map, params, "goods_code", "goods_code", false, false, false);
            HlpUtils.copyStringValue(map, params, "goods_name", "goods_name", false, false, false);
            PageBean page = new PageBean(map);
            LinkedList<LinkedHashMap<String, Object>> list = jxcReportService.findBuyYearReportListByPage(params, page);
            this.rewriteSpecNames(list);
            hr.setData(list);
            hr.setPage(page);
            hr.setCode(ErrorCode.CODE_SUCCESS);
        } catch (Exception e) {
            super.procException(hr, e);
        }
        return hr;
    }

    @ApiOperation(value = "进销存-统计报表-采购退货年度报表", notes = "进销存-统计报表-采购退货年度报表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", required = false, dataType = "string", paramType = "form"),
            @ApiImplicitParam(name = "pageNo", value = "页码", required = false, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "pageSize", value = "页大小，每页记录数", required = false, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "sorts", value = "排序设置，方式['property1 desc','property2']", required = false, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "totalRows", value = "总记录数，为了减少统计总记录数，一般从第二页开始前端提供totalRows", required = false, dataType = "int", paramType = "form")
    })
    @ResponseBody
    @RequestMapping(value = "/findBuyReturnYearReportListByPage.action", method = RequestMethod.POST)
    public HttpResult<Object> findBuyReturnYearReportListByPage() {
        HttpResult<Object> hr = new HttpResult<>();
        try {
            Map<String, Object> map = super.getParams(request);
            Map<String, Object> params = new HashMap<>(8);
            HlpUtils.copyIntegerValue(map, params, "dr", "dr", false, 0);
            HlpUtils.copyStringValue(map, params, "yyyy", "yyyy", false, false, false);
            HlpUtils.copyStringValue(map, params, "goods_code", "goods_code", false, false, false);
            HlpUtils.copyStringValue(map, params, "goods_name", "goods_name", false, false, false);
            PageBean page = new PageBean(map);
            LinkedList<LinkedHashMap<String, Object>> list = jxcReportService.findBuyReturnYearReportListByPage(params, page);
            this.rewriteSpecNames(list);
            hr.setData(list);
            hr.setPage(page);
            hr.setCode(ErrorCode.CODE_SUCCESS);
        } catch (Exception e) {
            super.procException(hr, e);
        }
        return hr;
    }

    @ApiOperation(value = "进销存-统计报表-采购商品报表", notes = "进销存-统计报表-采购商品报表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", required = false, dataType = "string", paramType = "form"),
            @ApiImplicitParam(name = "pageNo", value = "页码", required = false, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "pageSize", value = "页大小，每页记录数", required = false, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "sorts", value = "排序设置，方式['property1 desc','property2']", required = false, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "totalRows", value = "总记录数，为了减少统计总记录数，一般从第二页开始前端提供totalRows", required = false, dataType = "int", paramType = "form")
    })
    @ResponseBody
    @RequestMapping(value = "/findBuyGoodsReportListByPage.action", method = RequestMethod.POST)
    public HttpResult<Object> findBuyGoodsReportListByPage() {
        HttpResult<Object> hr = new HttpResult<>();
        try {
            Map<String, Object> map = super.getParams(request);
            Map<String, Object> params = new HashMap<>(8);
            HlpUtils.copyIntegerValue(map, params, "dr", "dr", false, 0);
            HlpUtils.copyStringValue(map, params, "goods_code", "goods_code", false, false, false);
            HlpUtils.copyStringValue(map, params, "goods_name", "goods_name", false, false, false);
            // 下单日期
            String order_date = HlpUtils.getString(map, "order_date");
            if (!HlpUtils.isEmpty(order_date)) {
                // 下单开始日期、下单结束日期
                this.dateRange(map, params, "order_date");
            }
            PageBean page = new PageBean(map);
            LinkedList<LinkedHashMap<String, Object>> list = jxcReportService.findBuyGoodsReportListByPage(params, page);
            this.rewriteSpecNames(list);
            hr.setData(list);
            hr.setPage(page);
            hr.setCode(ErrorCode.CODE_SUCCESS);
        } catch (Exception e) {
            super.procException(hr, e);
        }
        return hr;
    }

    @ApiOperation(value = "进销存-统计报表-采购退货商品报表", notes = "进销存-统计报表-采购退货商品报表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", required = false, dataType = "string", paramType = "form"),
            @ApiImplicitParam(name = "pageNo", value = "页码", required = false, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "pageSize", value = "页大小，每页记录数", required = false, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "sorts", value = "排序设置，方式['property1 desc','property2']", required = false, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "totalRows", value = "总记录数，为了减少统计总记录数，一般从第二页开始前端提供totalRows", required = false, dataType = "int", paramType = "form")
    })
    @ResponseBody
    @RequestMapping(value = "/findBuyReturnGoodsReportListByPage.action", method = RequestMethod.POST)
    public HttpResult<Object> findBuyReturnGoodsReportListByPage() {
        HttpResult<Object> hr = new HttpResult<>();
        try {
            Map<String, Object> map = super.getParams(request);
            Map<String, Object> params = new HashMap<>(8);
            HlpUtils.copyIntegerValue(map, params, "dr", "dr", false, 0);
            HlpUtils.copyStringValue(map, params, "goods_code", "goods_code", false, false, false);
            HlpUtils.copyStringValue(map, params, "goods_name", "goods_name", false, false, false);
            // 下单日期
            String order_date = HlpUtils.getString(map, "order_date");
            if (!HlpUtils.isEmpty(order_date)) {
                // 下单开始日期、下单结束日期
                this.dateRange(map, params, "order_date");
            }
            PageBean page = new PageBean(map);
            LinkedList<LinkedHashMap<String, Object>> list = jxcReportService.findBuyReturnGoodsReportListByPage(params, page);
            this.rewriteSpecNames(list);
            hr.setData(list);
            hr.setPage(page);
            hr.setCode(ErrorCode.CODE_SUCCESS);
        } catch (Exception e) {
            super.procException(hr, e);
        }
        return hr;
    }

    /**
     * 获取 key 开始时间、结束时间
     *
     * @param map
     * @param params
     * @param key
     * @throws ParseException
     */
    private void dateRange(Map<String, Object> map, Map<String, Object> params, String key) throws ParseException {
        if (!HlpUtils.isEmpty(key)) {
            // 实际发货日期
            String value = HlpUtils.getString(map, key);
            if (!HlpUtils.isEmpty(value)) {
                if (JSONUtil.isJsonArray(value)) {
                    List<String> value_list = JSON.parseArray(value, String.class);
                    // 要求发货开始日期、要求发货结束日期
                    if (value_list != null && value_list.size() == 2) {
                        Date date_begin = HlpUtils.string2Date(value_list.get(0), "yyyy-MM-dd");
                        Date date_end = HlpUtils.string2Date(value_list.get(1), "yyyy-MM-dd");
                        date_end = HlpUtils.getNextDate(date_end, 1);
                        params.put(key + "_begin", date_begin);
                        params.put(key + "_end", date_end);
                    }
                } else {
                    params.put(key, value);
                }
            }
        }
    }

    @ApiOperation(value = "进销存-统计报表-销售汇总报表", notes = "进销存-统计报表-销售汇总报表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "yyyy", value = "年份", required = false, dataType = "string", paramType = "form"),
    })
    @ResponseBody
    @RequestMapping(value = "/findSaleOrderCollectReportList.action", method = RequestMethod.POST)
    public HttpResult<Object> findSaleOrderCollectReportList() {
        HttpResult<Object> hr = new HttpResult<>();
        try {
            Map<String, Object> map = super.getParams(request);
            Map<String, Object> params = new HashMap<>(8);
            HlpUtils.copyIntegerValue(map, params, "dr", "dr", false, 0);
            HlpUtils.copyStringValue(map, params, "yyyy", "yyyy", false, false, false);
            LinkedList<LinkedHashMap<String, Object>> list = jxcReportService.findSaleOrderCollectReportList(params);
            hr.setData(list);
            hr.setCode(ErrorCode.CODE_SUCCESS);
        } catch (Exception e) {
            super.procException(hr, e);
        }
        return hr;
    }

    @ApiOperation(value = "进销存-统计报表-销售退货汇总报表", notes = "进销存-统计报表-销售退货汇总报表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "yyyy", value = "年份", required = false, dataType = "string", paramType = "form"),
    })
    @ResponseBody
    @RequestMapping(value = "/findSaleReturnCollectReportList.action", method = RequestMethod.POST)
    public HttpResult<Object> findSaleReturnCollectReportList() {
        HttpResult<Object> hr = new HttpResult<>();
        try {
            Map<String, Object> map = super.getParams(request);
            Map<String, Object> params = new HashMap<>(8);
            HlpUtils.copyIntegerValue(map, params, "dr", "dr", false, 0);
            HlpUtils.copyStringValue(map, params, "yyyy", "yyyy", false, false, false);
            LinkedList<LinkedHashMap<String, Object>> list = jxcReportService.findSaleReturnCollectReportList(params);
            hr.setData(list);
            hr.setCode(ErrorCode.CODE_SUCCESS);
        } catch (Exception e) {
            super.procException(hr, e);
        }
        return hr;
    }

    @ApiOperation(value = "进销存-统计报表-销售年度报表", notes = "进销存-统计报表-销售年度报表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", required = false, dataType = "string", paramType = "form"),
            @ApiImplicitParam(name = "pageNo", value = "页码", required = false, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "pageSize", value = "页大小，每页记录数", required = false, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "sorts", value = "排序设置，方式['property1 desc','property2']", required = false, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "totalRows", value = "总记录数，为了减少统计总记录数，一般从第二页开始前端提供totalRows", required = false, dataType = "int", paramType = "form")
    })
    @ResponseBody
    @RequestMapping(value = "/findSaleYearReportListByPage.action", method = RequestMethod.POST)
    public HttpResult<Object> findSaleYearReportListByPage() {
        HttpResult<Object> hr = new HttpResult<>();
        try {
            Map<String, Object> map = super.getParams(request);
            Map<String, Object> params = new HashMap<>(8);
            HlpUtils.copyIntegerValue(map, params, "dr", "dr", false, 0);
            HlpUtils.copyStringValue(map, params, "yyyy", "yyyy", false, false, false);
            HlpUtils.copyStringValue(map, params, "goods_code", "goods_code", false, false, false);
            HlpUtils.copyStringValue(map, params, "goods_name", "goods_name", false, false, false);
            PageBean page = new PageBean(map);
            LinkedList<LinkedHashMap<String, Object>> list = jxcReportService.findSaleYearReportListByPage(params, page);
            this.rewriteSpecNames(list);
            hr.setData(list);
            hr.setPage(page);
            hr.setCode(ErrorCode.CODE_SUCCESS);
        } catch (Exception e) {
            super.procException(hr, e);
        }
        return hr;
    }

    @ApiOperation(value = "进销存-统计报表-销售退货年度报表", notes = "进销存-统计报表-销售退货年度报表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", required = false, dataType = "string", paramType = "form"),
            @ApiImplicitParam(name = "pageNo", value = "页码", required = false, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "pageSize", value = "页大小，每页记录数", required = false, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "sorts", value = "排序设置，方式['property1 desc','property2']", required = false, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "totalRows", value = "总记录数，为了减少统计总记录数，一般从第二页开始前端提供totalRows", required = false, dataType = "int", paramType = "form")
    })
    @ResponseBody
    @RequestMapping(value = "/findSaleReturnYearReportListByPage.action", method = RequestMethod.POST)
    public HttpResult<Object> findSaleReturnYearReportListByPage() {
        HttpResult<Object> hr = new HttpResult<>();
        try {
            Map<String, Object> map = super.getParams(request);
            Map<String, Object> params = new HashMap<>(8);
            HlpUtils.copyIntegerValue(map, params, "dr", "dr", false, 0);
            HlpUtils.copyStringValue(map, params, "yyyy", "yyyy", false, false, false);
            HlpUtils.copyStringValue(map, params, "goods_code", "goods_code", false, false, false);
            HlpUtils.copyStringValue(map, params, "goods_name", "goods_name", false, false, false);
            PageBean page = new PageBean(map);
            LinkedList<LinkedHashMap<String, Object>> list = jxcReportService.findSaleReturnYearReportListByPage(params, page);
            this.rewriteSpecNames(list);
            hr.setData(list);
            hr.setPage(page);
            hr.setCode(ErrorCode.CODE_SUCCESS);
        } catch (Exception e) {
            super.procException(hr, e);
        }
        return hr;
    }

    @ApiOperation(value = "进销存-统计报表-销售商品报表", notes = "进销存-统计报表-销售商品报表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", required = false, dataType = "string", paramType = "form"),
            @ApiImplicitParam(name = "pageNo", value = "页码", required = false, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "pageSize", value = "页大小，每页记录数", required = false, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "sorts", value = "排序设置，方式['property1 desc','property2']", required = false, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "totalRows", value = "总记录数，为了减少统计总记录数，一般从第二页开始前端提供totalRows", required = false, dataType = "int", paramType = "form")
    })
    @ResponseBody
    @RequestMapping(value = "/findSaleGoodsReportListByPage.action", method = RequestMethod.POST)
    public HttpResult<Object> findSaleGoodsReportListByPage() {
        HttpResult<Object> hr = new HttpResult<>();
        try {
            Map<String, Object> map = super.getParams(request);
            Map<String, Object> params = new HashMap<>(8);
            HlpUtils.copyIntegerValue(map, params, "dr", "dr", false, 0);
            HlpUtils.copyStringValue(map, params, "goods_code", "goods_code", false, false, false);
            HlpUtils.copyStringValue(map, params, "goods_name", "goods_name", false, false, false);
            // 下单日期
            String order_date = HlpUtils.getString(map, "order_date");
            if (!HlpUtils.isEmpty(order_date)) {
                // 下单开始日期、下单结束日期
                this.dateRange(map, params, "order_date");
            }
            PageBean page = new PageBean(map);
            LinkedList<LinkedHashMap<String, Object>> list = jxcReportService.findSaleGoodsReportListByPage(params, page);
            this.rewriteSpecNames(list);
            hr.setData(list);
            hr.setPage(page);
            hr.setCode(ErrorCode.CODE_SUCCESS);
        } catch (Exception e) {
            super.procException(hr, e);
        }
        return hr;
    }

    @ApiOperation(value = "进销存-统计报表-销售退货商品报表", notes = "进销存-统计报表-销售退货商品报表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", required = false, dataType = "string", paramType = "form"),
            @ApiImplicitParam(name = "pageNo", value = "页码", required = false, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "pageSize", value = "页大小，每页记录数", required = false, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "sorts", value = "排序设置，方式['property1 desc','property2']", required = false, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "totalRows", value = "总记录数，为了减少统计总记录数，一般从第二页开始前端提供totalRows", required = false, dataType = "int", paramType = "form")
    })
    @ResponseBody
    @RequestMapping(value = "/findSaleReturnGoodsReportListByPage.action", method = RequestMethod.POST)
    public HttpResult<Object> findSaleReturnGoodsReportListByPage() {
        HttpResult<Object> hr = new HttpResult<>();
        try {
            Map<String, Object> map = super.getParams(request);
            Map<String, Object> params = new HashMap<>(8);
            HlpUtils.copyIntegerValue(map, params, "dr", "dr", false, 0);
            HlpUtils.copyStringValue(map, params, "goods_code", "goods_code", false, false, false);
            HlpUtils.copyStringValue(map, params, "goods_name", "goods_name", false, false, false);
            // 下单日期
            String order_date = HlpUtils.getString(map, "order_date");
            if (!HlpUtils.isEmpty(order_date)) {
                // 下单开始日期、下单结束日期
                this.dateRange(map, params, "order_date");
            }
            PageBean page = new PageBean(map);
            LinkedList<LinkedHashMap<String, Object>> list = jxcReportService.findSaleReturnGoodsReportListByPage(params, page);
            this.rewriteSpecNames(list);
            hr.setData(list);
            hr.setPage(page);
            hr.setCode(ErrorCode.CODE_SUCCESS);
        } catch (Exception e) {
            super.procException(hr, e);
        }
        return hr;
    }

    @ApiOperation(value = "进销存-统计报表-入库统计", notes = "进销存-统计报表-入库统计")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", required = false, dataType = "string", paramType = "form"),
            @ApiImplicitParam(name = "pageNo", value = "页码", required = false, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "pageSize", value = "页大小，每页记录数", required = false, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "sorts", value = "排序设置，方式['property1 desc','property2']", required = false, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "totalRows", value = "总记录数，为了减少统计总记录数，一般从第二页开始前端提供totalRows", required = false, dataType = "int", paramType = "form")
    })
    @ResponseBody
    @RequestMapping(value = "/findStockInbillReportListByPage.action", method = RequestMethod.POST)
    public HttpResult<Object> findStockInbillReportListByPage() {
        HttpResult<Object> hr = new HttpResult<>();
        try {
            Map<String, Object> map = super.getParams(request);
            Map<String, Object> params = new HashMap<>(8);
            HlpUtils.copyIntegerValue(map, params, "dr", "dr", false, 0);
            HlpUtils.copyStringValue(map, params, "warehouse_sid", "warehouse_sid", false, false, false);
            HlpUtils.copyStringValue(map, params, "goods_code", "goods_code", false, false, false);
            HlpUtils.copyStringValue(map, params, "goods_name", "goods_name", false, false, false);
            // 月份范围
            String yyyy_mm = HlpUtils.getString(map, "yyyy_mm");
            if (!HlpUtils.isEmpty(yyyy_mm)) {
                List<String> value_list = JSON.parseArray(yyyy_mm, String.class);
                // 月份开始、结束
                if (value_list != null && value_list.size() == 2) {
                    String yyyy_mm_begin = value_list.get(0);
                    String yyyy_mm_end = value_list.get(1);
                    params.put("yyyy_mm_begin", yyyy_mm_begin);
                    params.put("yyyy_mm_end", yyyy_mm_end);
                }
            }
            PageBean page = new PageBean(map);
            LinkedList<LinkedHashMap<String, Object>> list = jxcReportService.findStockInbillReportListByPage(params, page);
            this.rewriteSpecNames(list);
            hr.setData(list);
            hr.setPage(page);
            hr.setCode(ErrorCode.CODE_SUCCESS);
        } catch (Exception e) {
            super.procException(hr, e);
        }
        return hr;
    }

    @ApiOperation(value = "进销存-统计报表-出库统计", notes = "进销存-统计报表-出库统计")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", required = false, dataType = "string", paramType = "form"),
            @ApiImplicitParam(name = "pageNo", value = "页码", required = false, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "pageSize", value = "页大小，每页记录数", required = false, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "sorts", value = "排序设置，方式['property1 desc','property2']", required = false, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "totalRows", value = "总记录数，为了减少统计总记录数，一般从第二页开始前端提供totalRows", required = false, dataType = "int", paramType = "form")
    })
    @ResponseBody
    @RequestMapping(value = "/findStockOutbillReportListByPage.action", method = RequestMethod.POST)
    public HttpResult<Object> findStockOutbillReportListByPage() {
        HttpResult<Object> hr = new HttpResult<>();
        try {
            Map<String, Object> map = super.getParams(request);
            Map<String, Object> params = new HashMap<>(8);
            HlpUtils.copyIntegerValue(map, params, "dr", "dr", false, 0);
            HlpUtils.copyStringValue(map, params, "warehouse_sid", "warehouse_sid", false, false, false);
            HlpUtils.copyStringValue(map, params, "goods_code", "goods_code", false, false, false);
            HlpUtils.copyStringValue(map, params, "goods_name", "goods_name", false, false, false);
            // 月份范围
            String yyyy_mm = HlpUtils.getString(map, "yyyy_mm");
            if (!HlpUtils.isEmpty(yyyy_mm)) {
                List<String> value_list = JSON.parseArray(yyyy_mm, String.class);
                // 月份开始、结束
                if (value_list != null && value_list.size() == 2) {
                    String yyyy_mm_begin = value_list.get(0);
                    String yyyy_mm_end = value_list.get(1);
                    params.put("yyyy_mm_begin", yyyy_mm_begin);
                    params.put("yyyy_mm_end", yyyy_mm_end);
                }
            }
            PageBean page = new PageBean(map);
            LinkedList<LinkedHashMap<String, Object>> list = jxcReportService.findStockOutbillReportListByPage(params, page);
            this.rewriteSpecNames(list);
            hr.setData(list);
            hr.setPage(page);
            hr.setCode(ErrorCode.CODE_SUCCESS);
        } catch (Exception e) {
            super.procException(hr, e);
        }
        return hr;
    }

    @ApiOperation(value = "进销存-统计报表-盘盈盘亏", notes = "进销存-统计报表-盘盈盘亏")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", required = false, dataType = "string", paramType = "form"),
            @ApiImplicitParam(name = "pageNo", value = "页码", required = false, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "pageSize", value = "页大小，每页记录数", required = false, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "sorts", value = "排序设置，方式['property1 desc','property2']", required = false, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "totalRows", value = "总记录数，为了减少统计总记录数，一般从第二页开始前端提供totalRows", required = false, dataType = "int", paramType = "form")
    })
    @ResponseBody
    @RequestMapping(value = "/findStockInventoryReportListByPage.action", method = RequestMethod.POST)
    public HttpResult<Object> findStockInventoryReportListByPage() {
        HttpResult<Object> hr = new HttpResult<>();
        try {
            Map<String, Object> map = super.getParams(request);
            Map<String, Object> params = new HashMap<>(8);
            HlpUtils.copyIntegerValue(map, params, "dr", "dr", false, 0);
            HlpUtils.copyStringValue(map, params, "warehouse_sid", "warehouse_sid", false, false, false);
            HlpUtils.copyStringValue(map, params, "code", "code", false, false, false);
            HlpUtils.copyStringValue(map, params, "goods_code", "goods_code", false, false, false);
            HlpUtils.copyStringValue(map, params, "goods_name", "goods_name", false, false, false);
            // 盘点日期
            String check_date = HlpUtils.getString(map, "check_date");
            if (!HlpUtils.isEmpty(check_date)) {
                // 盘点日期开始日期、结束日期
                this.dateRange(map, params, "check_date");
            }
            PageBean page = new PageBean(map);
            LinkedList<LinkedHashMap<String, Object>> list = jxcReportService.findStockInventoryReportListByPage(params, page);
            this.rewriteSpecNames(list);
            hr.setData(list);
            hr.setPage(page);
            hr.setCode(ErrorCode.CODE_SUCCESS);
        } catch (Exception e) {
            super.procException(hr, e);
        }
        return hr;
    }

    @ApiOperation(value = "进销存-统计报表-采购金额Echart", notes = "进销存-统计报表-采购金额Echart")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", required = false, dataType = "string", paramType = "form"),
            @ApiImplicitParam(name = "pageNo", value = "页码", required = false, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "pageSize", value = "页大小，每页记录数", required = false, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "sorts", value = "排序设置，方式['property1 desc','property2']", required = false, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "totalRows", value = "总记录数，为了减少统计总记录数，一般从第二页开始前端提供totalRows", required = false, dataType = "int", paramType = "form")
    })
    @ResponseBody
    @RequestMapping(value = "/findBuyAmountQtyVisualChartList.action", method = RequestMethod.POST)
    public HttpResult<Object> findBuyAmountQtyVisualChartList() {
        HttpResult<Object> hr = new HttpResult<>();
        try {
            Map<String, Object> map = super.getParams(request);
            Map<String, Object> params = new HashMap<>(8);
            HlpUtils.copyStringValue(map, params, "yyyy", "yyyy", true, false, false);
            LinkedList<LinkedHashMap<String, Object>> list = jxcReportService.findBuyAmountQtyVisualChartList(params);
            hr.setData(list);
            hr.setCode(ErrorCode.CODE_SUCCESS);
        } catch (Exception e) {
            super.procException(hr, e);
        }
        return hr;
    }

    @ApiOperation(value = "进销存-统计报表-销售金额Echart", notes = "进销存-统计报表-销售金额Echart")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", required = false, dataType = "string", paramType = "form"),
            @ApiImplicitParam(name = "pageNo", value = "页码", required = false, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "pageSize", value = "页大小，每页记录数", required = false, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "sorts", value = "排序设置，方式['property1 desc','property2']", required = false, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "totalRows", value = "总记录数，为了减少统计总记录数，一般从第二页开始前端提供totalRows", required = false, dataType = "int", paramType = "form")
    })
    @ResponseBody
    @RequestMapping(value = "/findSaleAmountQtyVisualChartList.action", method = RequestMethod.POST)
    public HttpResult<Object> findSaleAmountQtyVisualChartList() {
        HttpResult<Object> hr = new HttpResult<>();
        try {
            Map<String, Object> map = super.getParams(request);
            Map<String, Object> params = new HashMap<>(8);
            HlpUtils.copyStringValue(map, params, "yyyy", "yyyy", true, false, false);
            LinkedList<LinkedHashMap<String, Object>> list = jxcReportService.findSaleAmountQtyVisualChartList(params);
            hr.setData(list);
            hr.setCode(ErrorCode.CODE_SUCCESS);
        } catch (Exception e) {
            super.procException(hr, e);
        }
        return hr;
    }

    /**
     * 重写商品货品规格名称
     *
     * @param list
     */
    private void rewriteSpecNames(LinkedList<LinkedHashMap<String, Object>> list) {
    }

    @ApiOperation(value = "进销存-统计报表-出入库统计")
    @ResponseBody
    @RequestMapping(value = "/findJxcStockInOutBillReport.action", method = RequestMethod.POST)
    @ClientSupplier(client = true, supplier = true)
    public HttpResult<Object> findJxcStockInOutBillReport() {
        HttpResult<Object> hr = new HttpResult<>();
        try {
            Map<String, Object> map = super.getParams(request);
            Map<String, Object> params = new HashMap<>(8);
            HlpUtils.copyIntegerValue(map, params, "yyyy", "yyyy", true, DateUtil.getYyyy(new Date()));
            HlpUtils.copyStringValue(map, params, "type", "type", true, false, false);
            HlpUtils.copyStringValue(map, params, "client_supplier", "client_supplier", true, false, false);
            HlpUtils.copyStringValue(map, params, "goods_spec", "goods_spec", true, false, false);
            PageBean page = new PageBean(map);
            List<JxcStockInOutBillReportVo> list = jxcReportService.findJxcStockInOutBillReport(params, page);
            hr.setData(list);
            hr.setPage(page);
            hr.setCode(ErrorCode.CODE_SUCCESS);
        } catch (Exception e) {
            super.procException(hr, e);
        }
        return hr;
    }

    @ApiOperation(value = "进销存-统计报表-出入库清单")
    @ResponseBody
    @RequestMapping(value = "/findJxcStockInOutBillInventory.action", method = RequestMethod.POST)
    @ClientSupplier(client = true, supplier = true)
    public HttpResult<Object> findJxcStockInOutBillInventory() {
        HttpResult<Object> hr = new HttpResult<>();
        try {
            Map<String, Object> map = super.getParams(request);
            Map<String, Object> params = new HashMap<>(8);
            HlpUtils.copyStringValue(map, params, "type", "type", true, false, false);
            HlpUtils.copyStringValue(map, params, "client_sid", "client_sid", false, false, false);
            HlpUtils.copyStringValue(map, params, "supplier_sid", "supplier_sid", false, false, false);
            HlpUtils.copyStringValue(map, params, "goods_sid", "goods_sid", false, false, false);
            PageBean page = new PageBean(map);
            List<JxcStockInOutBillInventoryVo> list = jxcReportService.findJxcStockInOutBillInventory(params, page);
            hr.setData(list);
            hr.setPage(page);
            hr.setCode(ErrorCode.CODE_SUCCESS);
        } catch (Exception e) {
            super.procException(hr, e);
        }
        return hr;
    }
}
